package cn.pet.service.manage.context;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author zwr
 * @version 1.0
 * @description TODO
 * @date 2023/2/17 20:06
 */
public class GlobalContext {

    private static Map<Integer,String> userMap = new ConcurrentHashMap<>();

    public static boolean add(Integer key,String value){
        try {
            userMap.put(key,value);
            return true;
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }
    }

    public static String get(Integer key){
        try {
            if (userMap.containsKey(key)){
                return userMap.get(key);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }


    public static boolean remove(Integer key){
        try {
            userMap.remove(key);
        }catch (Exception e){
            return false;
        }
        return true;
    }

    public static boolean isExist(Integer key){
        return userMap.containsKey(key);
    }
}
